package com.example.wastes.articles.controller;

import com.example.wastes.articles.service.ArticlesService;
import com.example.wastes.common.pojo.Articles;
import com.example.wastes.common.util.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class ArticlesController {
    @Autowired
    private ArticlesService articlesService;
    @GetMapping("/findAllArticles")
    @ApiOperation("分类详情查询所有")
    public R getAllArticles(){
        return new R(true,articlesService.findAll());
    }
    @PostMapping("/saveArticles")
    @ApiOperation("添加分类详情")
    public R saveArticles(@RequestBody Articles articles){
        return new R(articlesService.save(articles));
    }
    @PutMapping("/updateArticles")
    @ApiOperation("修改分类详情")
    public R updateArticles(@RequestBody Articles articles){
        return new R(articlesService.updateById(articles));
    }
    @DeleteMapping("/deleteArticles")
    @ApiOperation("删除分类详情")
    public R deleteArticles(Integer id){
        return new R(articlesService.removeById(id));
    }
    @GetMapping("/findArticlesMerge")
    @ApiOperation("通过分类查询分类详情article和articles两表多表联查")
    public R findArticlesMerge(Integer id){
        return new R(true,articlesService.findArticlesMerge(id));
    }
    @GetMapping("/findArticlesMerge1")
    @ApiOperation("通过分类查询分类详情article和articles两表多表联查只显示articles表")
    public R findArticlesMerge1(Integer id){
        return new R(true,articlesService.findArticlesMerge1(id));
    }
    @GetMapping("/findArticlesName")
    @ApiOperation("通过名字查金额")
    public R findArticlesName(String articlename){
        return new R(true,articlesService.findArticlesName(articlename));
    }
    //模糊查询
    @GetMapping("/findName")
    @ApiOperation("通过名字所有")
    public R findName(String articlename){
        return new R(true,articlesService.findName(articlename));
    }
}
